package com.farm.kaiping.controller;


import com.farm.kaiping.entity.MmChangeRecord;
import com.farm.kaiping.po.MmChangeRecordPO;
import com.farm.kaiping.service.MmChangeRecordService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.farm.common.util.PageParaUtils;
import com.farm.common.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 材料变更记录(MmChangeRecord)表控制层
 *
 * @author makejava
 * @since 2025-01-22 14:36:26
 */
@RestController
@RequestMapping("/mmChangeRecord")
@AllArgsConstructor
@Api(tags = "材料变更记录控制器")
public class MmChangeRecordController {

	private final MmChangeRecordService mmChangeRecordService;

	@ApiOperation(value = "分页查询材料变更记录", notes = "权限：view_mmChangeRecord_page")
	@PreAuthorize("@pms.hasPermission('ROLE_1','view_mmChangeRecord_page')")
	@PostMapping("/page")
	public R<Page<MmChangeRecord>> getMmChangeRecordPage(@RequestBody MmChangeRecordPO mmChangeRecordPO) {
		try{
		Page page = PageParaUtils.withdrawPageByParamType(mmChangeRecordPO);
		return R.ok(mmChangeRecordService.getMmChangeRecordPage(page, mmChangeRecordPO));
		}catch (Exception e){
			return R.failed(e.getMessage());
		}
	}
	
	@ApiOperation(value = "查询材料变更记录列表", notes = "权限：view_mmChangeRecord_list")
	@PreAuthorize("@pms.hasPermission('ROLE_1','view_mmChangeRecord_list')")
	@PostMapping("/list")
	public R<List<MmChangeRecord>> getMmChangeRecordList(@RequestBody MmChangeRecordPO mmChangeRecordPO) {
		try{
			return R.ok(mmChangeRecordService.getMmChangeRecordList(mmChangeRecordPO));
		}catch (Exception e){
			return R.failed(e.getMessage());
		}
	}

	@ApiOperation(value = "通过id查询材料变更记录", notes = "权限 view_mmChangeRecord_view")
	@GetMapping("/{id}" )
	@PreAuthorize("@pms.hasPermission('ROLE_1','view_mmChangeRecord_view')" )
	public R getById(@PathVariable("id" ) String id) {
		try{
			return R.ok(mmChangeRecordService.getById(id));
		}catch (Exception e){
			return R.failed(e.getMessage());
		}
	}
	
	@ApiOperation(value = "查询一条材料变更记录", notes = "权限：view_mmChangeRecord_one")
	@PreAuthorize("@pms.hasPermission('ROLE_1','view_mmChangeRecord_one')")
	@PostMapping("/one")
	public R<MmChangeRecord> getMmChangeRecord(@RequestBody MmChangeRecordPO mmChangeRecordPO) {
		try{
			return R.ok(mmChangeRecordService.getMmChangeRecord(mmChangeRecordPO));
		}catch (Exception e){
			return R.failed(e.getMessage());
		}
	}
	
	@ApiOperation(value = "新增材料变更记录", notes = "权限：view_mmChangeRecord_add")
	@PreAuthorize("@pms.hasPermission('ROLE_1','view_mmChangeRecord_add')")
	@PostMapping("/add")
	public R saveMmChangeRecord(@RequestBody MmChangeRecordPO mmChangeRecordPO) {
		try{
		    return R.ok(mmChangeRecordService.saveMmChangeRecord(mmChangeRecordPO));
		}catch (Exception e){
			return R.failed(e.getMessage());
		}
	}

	@ApiOperation(value = "修改材料变更记录", notes = "权限：view_mmChangeRecord_edit")
	@PreAuthorize("@pms.hasPermission('ROLE_1','view_mmChangeRecord_edit')")
	@PostMapping("/edit")
	public R updateMmChangeRecord(@RequestBody MmChangeRecordPO mmChangeRecordPO) {
		try{
		    return R.ok(mmChangeRecordService.updateMmChangeRecord(mmChangeRecordPO));
		}catch (Exception e){
			return R.failed(e.getMessage());
		}    
	}

	@ApiOperation(value = "通过id删除材料变更记录", notes = "权限：view_mmChangeRecord_del")
	@PreAuthorize("@pms.hasPermission('ROLE_1','view_mmChangeRecord_del')")
	@PostMapping("/del")
	public R removeMmChangeRecord(@RequestBody MmChangeRecordPO mmChangeRecordPO) {
		try{
		    return R.ok(mmChangeRecordService.removeMmChangeRecord(mmChangeRecordPO));
		}catch (Exception e){
			return R.failed(e.getMessage());
		}  
	}
	
}

